Create the Tekton Pipeline
Let's the build and deploy Tasks using Tekton Pipelines directly through the manifest.
We'll cover the following
The build-deploy Pipeline#
A Pipeline in Tekton is a collection of Tasks that we define and arrange in a specific order of execution. We’ll create a Pipeline of the build and deploy Tasks we created earlier. We’ve already created a file named pipeline-build-deploy.yaml, as shown in the widget below.
The Pipeline definition defines some parameters it needs to be able to run. It consists of two Tasks: one to build an image and the other to deploy the service. Each Task must have a name and a taskRef that points to a Task available in the cluster. In the build-deploy Pipeline, we defined a Task named build, which references the build Task, and another named deploy, which references the deploy Task. We should see this in the tasks field in the Pipeline definition.
We can use the results from one Task as input for another Task. In our Pipeline, we used the image output from the build Task as the value for the image parameter of the deploy Task. We can use the syntax $(tasks.<task>.results.<variable>) to read the necessary variable from a Task result. On lines 35 and 36, we specified the value for the image parameter as follows:
- name: image
value: $(tasks.build.results.image)
Run the command given in 1_buildDeploy.sh to create the build-deploy Pipeline.
The image below summarizes the process:
Execute the build-deploy Pipeline#
Similar to a TaskRun, we can execute a Pipeline using a PipelineRun. Let’s try our newly created Pipeline to see if it works. This time, we’ll use the kubectl command instead of the Dashboard. We’ve already created a file named pipelinerun.yaml, shown in the widget below.
In this manifest, we defined a PipelineRun that will execute the build-deploy Pipeline. The Pipeline to execute is referenced using the PipelineRef field. In this file, we also specified the values for some parameters needed for the Pipeline to be executed. In the image parameter value, replace the <username> with your Docker Hub’s username.
Run the command in 2_pipelineRun.sh to execute the Pipeline. It’ll take a while to execute, but we can check the status of the execution using the following command:
kubectl get pipelineruns
On a successful run of the command above, the service should be deployed and available on tekton-test.default.<EXTERNAL_IP>.sslip.io.
Note: Here’s the command that you can use to check the external IP of the cluster:
kubectl get svc -n kourier-system -o yaml | grep ip:
The figure below shows the build Task running on the Dashboard under the “PipelineRuns” tab.
We can see details about the PipelineRun using the following command:
kubectl describe pipelinerun build-deploy
Note: We should replace the
<USERNAME>in thepipelinerun.yamlfile first and then click the “Run” button in the widget shown below.To run all the commands written in a
.shfile, just type./file-name.shin the terminal.
/
The build and deploy Tasks
Wrap-up and Quiz